<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            background-color: red;
            width:100px;
            height: 100px;
            margin:10px;
            color:#fff;
        }
        div:nth-child(2){
            background-color: blue;
            position: sticky;
            top:50px;
        }
    </style>
</head>
<body>
    <div>div1</div>
    <div>div2</div>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div>div3</div>
</body>
</html>